import { Component, OnInit, AfterContentChecked} from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  title = '';
  activeId = 0;
  tabBars: any = [
    { title: '外卖', icon: 'icon-dinner', route: 'msite' },
    { title: '搜索', icon: 'icon-takeabreak', route: 'search' },
    { title: '订单', icon: 'icon-infopersonal', route: 'order' },
    { title: '我的', icon: 'icon-nickname', route: 'profile' },
  ];

  // tslint:disable-next-line: use-lifecycle-interface
  ngOnInit(): void {
    // console.log(window.location.pathname);
    switch (window.location.pathname){
      case '/msite': this.activeId = 0; break;
      case '/search': this.activeId = 1; break;
      case '/order': this.activeId = 2; break;
      case '/profile': this.activeId = 3; break;
    }
    if (this.activeId){
      this.title = this.tabBars[this.activeId].title;
    }
  }

  tabChange(id: number): any {
    // if (e.route === 'msite') {
    //   this.title = '';
    // } else {
    //   this.title = e.title;
    // }
    this.activeId = id;
    if (this.activeId === 0){
      this.title = '';
    }else{
      this.title = this.tabBars[this.activeId].title;
    }
  }
}
